﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;

namespace MailTo
{
    public partial class frm_main : Form
    {
        //Some shit to keep track of
        String Protocol; //http or https
        String GAFD; //User is using gafd or not
        String Domain;
        Boolean AllUsers;
        Settings LocalSettings;

        
        public frm_main(Settings PassedSettings)
        {
            this.LocalSettings = PassedSettings;
            InitializeComponent();
        }

        private void rb_norm_gmail_CheckedChanged(object sender, EventArgs e)
        {
            if (rb_norm_gmail.Checked == true)
            {
                rb_gafd.Checked = false;
                this.tb_gafd.Enabled = false;
            }
        }

        private void rb_gafd_CheckedChanged(object sender, EventArgs e)
        {
            if (rb_gafd.Checked == true)
            {
                rb_norm_gmail.Checked = false;
                this.tb_gafd.Enabled = true;
            }
        }

        private void llbl_about_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            AboutBox About = new AboutBox();
            About.Show();
        }

        private void btn_Submit_Click(object sender, EventArgs e)
        {
            //Is GAFD checked? 
            if (rb_gafd.Checked == true)
            {
                GAFD = "true";
                if (tb_gafd.Text != "")
                {
                    Domain = tb_gafd.Text;
                }
                else
                {//User did not type in a domain
                    MessageBox.Show("You must specify a domain", "Error");
                    this.Show();
                }
            }//end GAFD true check
            else
            {
                GAFD = "false";
                Domain = "";
            }

            //Get the selected protocol
            if (this.rb_http.Checked == true)
            {
                this.Protocol = "http://";
            }
            else
            {
                this.Protocol = "https://";
            }

            //All Users?
            if (cb_AllUsers.Checked == true)
            {
                AllUsers = true;
            }
            else AllUsers = false;

            //Store the variables in registry
            this.LocalSettings.Set(new string[] { Domain, Protocol, GAFD }, AllUsers);
            this.Close();
        }//End submit
    }
}
